package ogs.game;

import java.io.IOException;
import java.net.InetSocketAddress;

import ogs.game.core.GameHandler;
import ogs.game.core.MsgCodecFactory;
import ogs.game.utils.FlashPolicyHandler;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AncientMain 
{
	public static final int FLASH_POLICY_PORT = 843;
	public static final int GAME_PORT = 8072;

	Logger logger = LoggerFactory.getLogger(AncientMain.class);
	
	public static void main(String[] args) throws IOException
	{
		NioSocketAcceptor policyAcceptor = new NioSocketAcceptor();
		policyAcceptor.getFilterChain().addLast("logger", new LoggingFilter());
		policyAcceptor.setHandler(new FlashPolicyHandler());
		policyAcceptor.bind(new InetSocketAddress(FLASH_POLICY_PORT));
		
		// TODO: Database initialization
		
		
		NioSocketAcceptor acceptor = new NioSocketAcceptor();
		DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
		chain.addLast("logger", new LoggingFilter());
		chain.addLast("codec", new ProtocolCodecFilter(new MsgCodecFactory()));
		acceptor.setHandler(new GameHandler());
		acceptor.bind(new InetSocketAddress(GAME_PORT));
	}
}

